package cn.com.pg.b2b.pd.truck.appointment.management.service.model.entity;

import cn.com.pg.b2b.pd.truck.appointment.management.service.model.dto.LineStepDTO;
import com.baomidou.mybatisplus.annotation.TableId;

import java.time.LocalDateTime;
import java.io.Serializable;

/**
 * <p>
 * 线路节点
 * </p>
 *
 * @author 王开琦
 * @since 2023-06-08
 */
public class LineStep implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 创建时间
     */
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    private LocalDateTime updateTime;

    /**
     * 创建人ID
     */
    private Integer createUserId;

    /**
     * 更新人ID
     */
    private Integer updateUserId;

    /**
     * 是否有效：0-不可用，1-可用
     */
    private Boolean isValidFlag = true;

    /**
     * 线路节点ID
     */
    private Integer lineStepId;

    /**
     * 线路ID
     */
    @TableId
    private Integer lineId;

    /**
     * 节点序号
     */
    private Integer index;

    /**
     * 节点机构
     */
    private Integer orgId;

    /**
     * 多组路由编号
     */
    private Integer routeGroup;

    /**
     * DTO 转换为插入数据库对象
     *
     * @param lineStepDTO
     * @return 插入数据库对象
     */
    public static LineStep from(LineStepDTO lineStepDTO) {
        LineStep lineStep = new LineStep();
        //复制所有属性
        lineStep.setCreateTime(LocalDateTime.now());
        lineStep.setCreateTime(LocalDateTime.now());
        lineStep.setUpdateUserId(1);
        lineStep.setUpdateUserId(1);
        lineStep.setLineId(lineStep.lineId);
        //Id自增
        lineStep.setIndex(lineStep.getIndex());
        lineStep.setOrgId(lineStep.getOrgId());
        lineStep.setRouteGroup(lineStep.getRouteGroup());
        return lineStep;
    }

    /**
     * DTO 转换为更新数据库对象
     *
     * @param lineStep    entity
     * @param lineStepDTO dto
     * @return 要更新的数据库对象
     */
    public static LineStep from(LineStep lineStep, LineStepDTO lineStepDTO) {
        lineStep.setUpdateUserId(1);
        lineStep.setUpdateTime(LocalDateTime.now());
        //其余属性不为空则设置
        lineStep.setIndex(lineStepDTO.getIndex() != null ? lineStepDTO.getIndex() : lineStep.getIndex());
        lineStep.setIsValidFlag(lineStepDTO.getIsValidFlag() != null ? lineStepDTO.getIsValidFlag() : lineStep.getIsValidFlag());
        lineStep.setOrgId(lineStepDTO.getOrgId() != null ? lineStepDTO.getOrgId() : lineStep.getOrgId());
        lineStep.setRouteGroup(lineStepDTO.getRouteGroup() != null ? lineStepDTO.getRouteGroup() : lineStep.getRouteGroup());
        lineStep.setLineId(lineStepDTO.getLineId() != null ? lineStepDTO.getLineId() : lineStep.lineId);
        return lineStep;
    }


    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public LocalDateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }

    public Integer getCreateUserId() {
        return createUserId;
    }

    public void setCreateUserId(Integer createUserId) {
        this.createUserId = createUserId;
    }

    public Integer getUpdateUserId() {
        return updateUserId;
    }

    public void setUpdateUserId(Integer updateUserId) {
        this.updateUserId = updateUserId;
    }

    public Boolean getIsValidFlag() {
        return isValidFlag;
    }

    public void setIsValidFlag(Boolean isValidFlag) {
        this.isValidFlag = isValidFlag;
    }

    public Integer getLineStepId() {
        return lineStepId;
    }

    public void setLineStepId(Integer lineStepId) {
        this.lineStepId = lineStepId;
    }

    public Integer getLineId() {
        return lineId;
    }

    public void setLineId(Integer lineId) {
        this.lineId = lineId;
    }

    public Integer getIndex() {
        return index;
    }

    public void setIndex(Integer index) {
        this.index = index;
    }

    public Integer getOrgId() {
        return orgId;
    }

    public void setOrgId(Integer orgId) {
        this.orgId = orgId;
    }

    public Integer getRouteGroup() {
        return routeGroup;
    }

    public void setRouteGroup(Integer routeGroup) {
        this.routeGroup = routeGroup;
    }

    @Override
    public String toString() {
        return "LineStep{" + "createTime=" + createTime + ", updateTime=" + updateTime + ", createUserId=" + createUserId + ", updateUserId=" + updateUserId + ", isValidFlag=" + isValidFlag + ", lineStepId=" + lineStepId + ", lineId=" + lineId + ", index=" + index + ", orgId=" + orgId + ", routeGroup=" + routeGroup + "}";
    }

    public LineStepDTO to() {
        LineStepDTO lineStepDTO = new LineStepDTO();
        lineStepDTO.setLineStepId(lineStepId);
        lineStepDTO.setLineId(lineId);
        lineStepDTO.setIndex(index);
        lineStepDTO.setOrgId(orgId);
        lineStepDTO.setRouteGroup(routeGroup);
        lineStepDTO.setIsValidFlag(isValidFlag);
        return lineStepDTO;
    }
}
